package com.bilibili.juc.set;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.TimerTask;

public class MyTimerTask extends TimerTask {

    private LocalDateTime endDate;

    public MyTimerTask() {
        String dateStr = "2023-11-11 11:11:11";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        endDate = LocalDateTime.parse(dateStr,dtf);
        System.out.println("\t\t\t\t欢迎你们购物 ");
        System.out.println("距离双11 还有 ");
    }

    @Override
    public void run() {
        LocalDateTime startDate = LocalDateTime.now();
        Duration duration = Duration.between(startDate, endDate);
   /*     String msg = "\t\t\t\t欢迎你们购物 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" +
                "\t距离双11 还有 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" +
                duration.toDays() + " 天 " + duration.toHoursPart() + " 小时 "
                + duration.toMinutesPart() + " 分 " + duration.toSecondsPart() + " 秒 ";*/

        String msg =  duration.toDays() + " 天 " + duration.toHoursPart() + " 小时 "
                + duration.toMinutesPart() + " 分 " + duration.toSecondsPart() + " 秒 ";

        System.out.print("\r" + msg);
    }
}
